          package com.coconet.gas.security.Handler;


import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

          /**
           * 自定403返回值
           *
           * @author hackyo
           * Created on 2017/12/9 20:10.
           */
          @Component
          public class RestAccessDeniedHandler implements AccessDeniedHandler {

              @Override
              public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e) {
                  response.setHeader("Access-Control-Allow-Origin", "*");
                  response.setCharacterEncoding("UTF-8");
                  try {
                      response.getWriter().println("没有权限");
                  } catch (IOException e1) {
                      // TODO Auto-generated catch block
                      e1.printStackTrace();
                  }
                  response.setStatus(403);
              }

          }